package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCPredictiveMaintenance;

public class MaintenanceEvent1Dto {

    private double mileage;
    private int clutchWearSignal;

    public double getMileage() {
        return mileage;
    }

    public void setMileage(double mileage) {
        this.mileage = mileage;
    }

    public int getClutchWearSignal() {
        return clutchWearSignal;
    }

    public void setClutchWearSignal(int clutchWearSignal) {
        this.clutchWearSignal = clutchWearSignal;
    }

    public static MaintenanceEvent1Dto parseProto(LCPredictiveMaintenance.MaintenanceEvent1 maintenanceEvent1){
        MaintenanceEvent1Dto maintenanceEvent1Dto = new MaintenanceEvent1Dto();
        maintenanceEvent1Dto.setMileage(maintenanceEvent1.getMileage());
        maintenanceEvent1Dto.setClutchWearSignal(maintenanceEvent1.getClutchWearSignal());
        return maintenanceEvent1Dto;
    }

    /**
     * 解析成String拼接字符串
     * @param maintenanceEvent1
     * @return
     */
    public static String parseString(LCPredictiveMaintenance.MaintenanceEvent1 maintenanceEvent1){
        return EntityConvert.convert(
                maintenanceEvent1.getMileage(),
                maintenanceEvent1.getClutchWearSignal());
    }

    /**
     * 反解析成PB对象
     * @param str
     * @return
     */
    public static LCPredictiveMaintenance.MaintenanceEvent1 parsePB(String str){
        LCPredictiveMaintenance.MaintenanceEvent1.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(str);
            if(null!=revert && revert.length>=5){
                builder = LCPredictiveMaintenance.MaintenanceEvent1.newBuilder();
                builder.setMileage(Integer.valueOf(revert[0]));
                builder.setClutchWearSignal(Integer.valueOf(revert[1]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }
}
